/* eslint-disable */
// @ts-ignore
import request from '@/utils/http';

import * as API from './types';

/** aliFile POST /oss/aliFile */
export async function ossAliFileUsingPost({
  body,
  file,
  options,
}: {
  body: {};
  file?: File;
  options?: { [key: string]: unknown };
}) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as { [key: string]: any })[ele];

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<API.xiangyingstring>('/oss/aliFile', {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: formData,
    ...(options || {}),
  });
}

/** completeUpload POST /oss/complete */
export async function ossCompleteUsingPost({
  params,
  options,
}: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.ossCompleteUsingPostParams;
  options?: { [key: string]: unknown };
}) {
  return request<API.xiangyingMinioVo>('/oss/complete', {
    method: 'POST',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** deleteMinioUrl POST /oss/deleteMinioUrl */
export async function ossDeleteMinioUrlUsingPost({
  body,
  options,
}: {
  body: API.FileInfo;
  options?: { [key: string]: unknown };
}) {
  return request<API.xiangyingboolean>('/oss/deleteMinioUrl', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** downMinioUrl POST /oss/downMinioUrl */
export async function ossDownMinioUrlUsingPost({
  params,
  options,
}: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.ossDownMinioUrlUsingPostParams;
  options?: { [key: string]: unknown };
}) {
  return request<API.xiangyingboolean>('/oss/downMinioUrl', {
    method: 'POST',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** initiateUpload POST /oss/initiate */
export async function ossInitiateUsingPost({
  params,
  options,
}: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.ossInitiateUsingPostParams;
  options?: { [key: string]: unknown };
}) {
  return request<API.xiangyingMinioVo>('/oss/initiate', {
    method: 'POST',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** saveMinioFile POST /oss/saveMinioFile */
export async function ossSaveMinioFileUsingPost({
  body,
  file,
  options,
}: {
  body: {};
  file?: File;
  options?: { [key: string]: unknown };
}) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as { [key: string]: any })[ele];

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<API.xiangyingFileInfo>('/oss/saveMinioFile', {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: formData,
    ...(options || {}),
  });
}

/** saveMinioFileAsync POST /oss/saveMinioFileAsync */
export async function ossSaveMinioFileAsyncUsingPost({
  body,
  file,
  options,
}: {
  body: {};
  file?: File;
  options?: { [key: string]: unknown };
}) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as { [key: string]: any })[ele];

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<API.xiangyingFileInfo>('/oss/saveMinioFileAsync', {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: formData,
    ...(options || {}),
  });
}

/** uploadPart POST /oss/upload */
export async function ossUploadUsingPost({
  params,
  body,
  file,
  options,
}: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.ossUploadUsingPostParams;
  body: {};
  file?: File;
  options?: { [key: string]: unknown };
}) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as { [key: string]: any })[ele];

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<API.xiangyingMinioVo>('/oss/upload', {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    params: {
      ...params,
    },
    data: formData,
    ...(options || {}),
  });
}
